package com.herench.bs.handler;

import com.herench.bs.agent.IHospitalAgent;
import com.herench.bs.annotation.Handler;
import com.herench.bs.support.AbstractMessageHandler;
import com.herench.bs.support.RequestMessage;
import com.herench.bs.support.ResponseMessage;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.Map;

/**
 * Created by ThinkPad on 2017/9/23.
 */
@Component
@Handler(code = "100219",name="获取协议书接口")
public class AgreementHandler extends AbstractMessageHandler {

    @Override
    protected ResponseMessage innerHandler(RequestMessage requestMessage) throws Exception {
        ResponseMessage responseMessage = new ResponseMessage(requestMessage.getId());
        String channelCode =requestMessage.getArgsPropertyStringValue("sysCode");
        Assert.hasLength(channelCode,"sysCode 为空");
        String type = requestMessage.getArgsPropertyStringValue("type");
        Assert.hasLength(type,"type 为空");
        IHospitalAgent agent = getCleverClinicContext().getApplicationContext().getBean(IHospitalAgent.class);
        String hospitalCode = getCleverClinicContext().getHospitalCodeByChannelCode(channelCode);
        Map<String,Object> res = agent.loadAgreement(hospitalCode,type);
        responseMessage.setData(res);
        getPropertiesFromInvokerResultMap(responseMessage,res);
        return responseMessage;
    }
}
